<?php
class User_Model_PositionRightMap 
{
 
	private $_table;
	//Initalizing Db Table  
	public function __construct(){
		$this->_table = new User_Model_DbTable_PositionRightMap();
	}
	
	public function add($row){
		return $this->_table->insert($row);
	}
	/**
	 * 根据条件获取指定模块信息
	 */
	public function getByCond($cond=array(),$type,$order,$count=20, $offset=0){
		$table = $this->_table->info('name');		
		$select = $this->_table->select()->from($table, $type);
		if(isset($cond['ur_id']) && $cond['ur_id']){
			$select->where('ur_id = ?',$cond['ur_id']);
		}
		if( $type =='count(*)'){
            return $this->_table->getAdapter()->fetchOne($select);
        }
		$select->order($order);
		if($count==0){
			return $this->_table->fetchAll($select);
		}
		$select->limit($count,$offset);
		$rowset = $this->_table->fetchAll($select);
		return $rowset;	
	}
	
	public function getByPid($pid){
		$table = $this->_table->info('name');
		$select = $this->_table->select()->from($table, '*');
		$select->where('position_id = ?',$pid);
		return $this->_table->fetchAll($select)->toArray();
	}
	
	public function deleteBy($pid,$ur_id){		
		$where = $this->_table->getAdapter()->quoteInto('position_id = ?', $pid);
		$where .= $this->_table->getAdapter()->quoteInto(' and ur_id = ?', $ur_id);
		$rows_affected = $this->_table->delete($where);
		return $rows_affected;
	}

	
}